 package cst.a729yt.recyclerview;

 import android.os.Bundle;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;

 import java.util.ArrayList;
 import java.util.List;

 public class MainActivity extends AppCompatActivity {
     private RecyclerView recyclerView;
     private RecyclerView.LayoutManager layoutManager;
     private MyAdapter adapter;
     private List<ArticleBean> list;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         recyclerView =
                 (RecyclerView) findViewById(R.id.recycler1);
         list = getData();

         layoutManager = new LinearLayoutManager(this);
         recyclerView.setLayoutManager(layoutManager);

         adapter=new MyAdapter(this);
         adapter.setList(list);
         recyclerView.setAdapter(adapter);

     }

     private List<ArticleBean> getData() {
         List<ArticleBean> list = new ArrayList<ArticleBean>();
         ArticleBean art;
         art = new ArticleBean();
         art.setArticleId(1);
         art.setTitle("标题1");
         art.setImgid(R.drawable.f1);
         art.setTime("2017-4-1 15:16");
         art.setDescription("描述1");
         list.add(art);


         art = new ArticleBean();
         art.setArticleId(1);
         art.setTitle("标题2");
         art.setImgid(R.drawable.f2);
         art.setTime("2017-4-1 15:16");
         art.setDescription("描述2");
         list.add(art);


         art = new ArticleBean();
         art.setArticleId(1);
         art.setTitle("标题3");
         art.setImgid(R.drawable.f3);
         art.setTime("2017-4-1 15:16");
         art.setDescription("描述3");
         list.add(art);


         return list;
     }

}
